import 'package:cbec_app/components/base/base_ctr.dart';
import 'package:cbec_app/components/http/network.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:umeng_common_sdk/umeng_common_sdk.dart';

import '../../../utils/EventMgr.dart';

///售后详情控制器
class AfterSaleController extends BaseController {
  Map? data;
  int payType = 1;
  int refundType = 1;
  String logisticsSelectedDataa = '顺丰速运';

  TextEditingController logisticsTec = TextEditingController();

  @override
  void onInit() {
    final String id = Get.arguments ?? '';
    getdetail(id);
    super.onInit();
    UmengCommonSdk.onPageStart('售后详情');
  }

  ///获取详情
  void getdetail(String id) {
    Tools.showLoading();
    Network.afterSalesDetail(id).then((value) {
      data = value;
      if (data!['payType'] != null) {
        payType = data!['payType'];
      } else {
        payType = 1;
      }

      if (data!['refundType'] != null) {
        refundType = data!['refundType'];
      } else {
        refundType = 1;
      }
      update();
      Tools.hideLoading();
    }).catchError((error) {
      Tools.hideLoading();
    });
  }

  ///上传物流
  void shipping(Map<String, dynamic> params) {
    Tools.showLoading();
    Network.shipping(params).then((value) {
      EventMgr.send(EventType.refreshOrderList);
      Tools.showToast('上传成功');
      update();
      Tools.hideLoading();
      Get.back();
    }).catchError((error) {
      Tools.hideLoading();
    });
  }

  @override
  void onClose() {
    super.onClose();
    UmengCommonSdk.onPageEnd('售后详情');
  }
}
